import random
import time

# 装饰器build_log
def build_log(fn):
    def inner(*args, **kwargs):
        print(f"log input check {args=}, {kwargs=}")
        res = fn(*args, **kwargs)
        formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        print(f"log output time {formatted_time=}")
        return res
    return inner

# 装饰器time_cost
def time_cost(fn):
    def inner(*args, **kwargs):
        start = time.time()
        sleep = random.randint(1,10)
        print(f"time sleep: {sleep}")
        time.sleep(sleep)
        res = fn(*args, **kwargs)
        over = time.time()
        print(f"time cost: {over - start}")
        return res
    return inner

# 装饰器嵌套inner方法执行顺序 time_cost->build_log->doit->build_log->time_cost
@time_cost
@build_log
def doit(name):
    print(f"{name=}")

doit('xbox')